// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <melon/io/io_buf.h>
#include <turbo/flags/flag.h>
#include <string>
#include <pollux/common/file/file_systems.h>
#include <pollux/common/file/utils.h>

TURBO_DECLARE_FLAG(std::string, source_root_dir);
TURBO_DECLARE_FLAG(std::string, dest_root_dir);
TURBO_DECLARE_FLAG(std::string, trace_file_op);
TURBO_DECLARE_FLAG(std::string, trace_query_id);
TURBO_DECLARE_FLAG(std::string, trace_task_id);

namespace kumo::pollux::tool::trace {

/// The trace replay runner. It is configured through a set of gflags passed
/// from replayer tool command line.
class TraceFileToolRunner {
 public:
  TraceFileToolRunner();
  virtual ~TraceFileToolRunner() = default;

  /// Initializes the trace file tool runner by setting the pollux runtime
  /// environment for the trace file operations. It is invoked before run().
  virtual void init();

  /// Runs the trace file operations.
  void run();

 private:
  // List all the files in the source root dir recursively.
  void listFiles(const std::string& path);

  void copyFiles() const;

  const std::string sourceRootDir_;
  const std::string destRootDir_;
  std::shared_ptr<filesystems::FileSystem> sourceFs_;
  std::shared_ptr<filesystems::FileSystem> destFs_;
  std::vector<std::string> sourceFiles_;
};

} // namespace kumo::pollux::tool::trace
